package com.mvc4g.example.mockup.client.view.templates;

import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.mvc4g.client.Controller;
import com.mvc4g.example.mockup.client.view.views.AbstractView;
import com.mvc4g.example.mockup.client.view.widgets.FooterWidget;
import com.mvc4g.example.mockup.client.view.widgets.HeaderWidget;

public class LoggedTemplate extends AbstractView {

	private SimplePanel body = null;
	private HeaderWidget header = null;
	private FooterWidget footer = null;

	@Override
	protected Widget createWidget() {
		
		body = new SimplePanel();
		header = new HeaderWidget();
		footer = new FooterWidget();

		VerticalPanel mainPanel = new VerticalPanel();
		mainPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		mainPanel.setBorderWidth(5);

		mainPanel.add(header);
		mainPanel.add(body);
		mainPanel.add(footer);

		return mainPanel;
	}

	public void changePage(AbstractView newView, String historyToken) {
		body.clear();
		newView.setVisible(true);
		newView.init();
		body.add(newView);
		
		if(historyToken != null){
			History.newItem(historyToken, false);
		}
	}

	@Override
	public void setController(Controller controller) {
		// No need of a controller
	}

	@Override
	public void init() {
		// Nothing to do here
	}

}
